package web

import (
	"context"

	"portal/internal/errorx"
	"portal/internal/svc"
	"portal/internal/types"
	"portal/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type NewsDetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
	newsModel model.AwNewsModel
}

func NewNewsDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewsDetailLogic {
	return &NewsDetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
		newsModel: model.NewAwNewsModel(svcCtx.Orm),
	}
}

func (l *NewsDetailLogic) NewsDetail(req *types.NewsDetailRequest) (resp *types.CommonResponse, err error) {
	// todo: add your logic here and delete this line
	newsDto,err := l.newsModel.GetDetailOne(l.ctx,nil,req.NewsPath)
	if err != nil {
		return nil,errorx.NewBizError(500,err.Error())
	}
	newsVo := &types.NewsVo{
		NewsId: newsDto.NewsId,
		CoverImg: newsDto.CoverImg.String,
		NewsTitle: newsDto.NewsTitle,
		NewsDesc: newsDto.NewsDesc,
		NewsContent: newsDto.NewsContent.String,
		NewsPath: newsDto.NewsPath.String,
		Typename: newsDto.Typename,
		PublishTime: newsDto.PublishTime,
		UpdateTime: newsDto.UpdateTime,
	}
	return &types.CommonResponse{
		Status: 200,
		Msg: "查询成功",
		Data: newsVo,
	},nil
}
